package com.situ.day08;

import java.util.ArrayList;
import java.util.Scanner;

import com.situ.day05.Student;

public class StudentManger {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		ArrayList<Student> list = new ArrayList<Student>();
		while (true) {
			System.out.println("请输入学生的id：");
			int id = scanner.nextInt();
			System.out.println("请输入学生的姓名：");
			String name = scanner.next();
			System.out.println("请输入学生的年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入学生的班级：");
			String className = scanner.next();
			Student student2 = new Student(id, name, age, className);
			list.add(student2);
			System.out.println("要退出输入0");
			int count = scanner.nextInt();
			if (count == 0) {
				break;
			}
		}
		
		while (true) {
			System.out.println("----------------------");
			System.out.println("根据id查找输入：1");
			System.out.println("根据名字查找输入：2");
			System.out.println("根据年龄查找输入：3");
			System.out.println("根据班级查找输入：4");
			System.out.println("退出程序：0");
			System.out.println("----------------------");
			int type = scanner.nextInt();
			if (type == 0) {
				System.out.println("退出程序");
				break;
			}

			switch (type) {
			case 1:// 根据id查找
				System.out.println("根据id搜索");
				int searchId = scanner.nextInt();
				boolean isSearchIdFound = false;
				for (Student student : list) {
					if (student.getId() == searchId) {
						System.out.println(student);
						isSearchIdFound = true;
					}
				}
				if (isSearchIdFound == false) {
					System.out.println("没这个人");
				}
				break;
			case 2:// 根据名字查找
				System.out.println("根据名字搜索");
				String searchName = scanner.next();
				boolean isSearchNameFound = false;
				for (Student student : list) {
					if (student.getName().equals(searchName)) {
						System.out.println(student);
						isSearchNameFound = true;
					}
				}
				if (isSearchNameFound == false) {
					System.out.println("没这个人");
				}
				break;
			case 3:// 根据名字查找
				System.out.println("根据年龄搜索");
				int searchAge = scanner.nextInt();
				boolean isSearchAgeFound = false;
				for (Student student : list) {
					if (student.getAge() == searchAge) {
						System.out.println(student);
						isSearchAgeFound = true;
					}
				}
				if (isSearchAgeFound == false) {
					System.out.println("没这个人");
				}
				break;
			case 4:// 根据班级查找
				System.out.println("根据班级搜索");
				String searchClassName = scanner.next();
				boolean isSearchClassNameFound = false;
				for (Student student : list) {
					if (student.getClassName().equals(searchClassName)) {
						System.out.println(student);
						isSearchClassNameFound = true;
					}
				}
				if (isSearchClassNameFound == false) {
					System.out.println("没这个人");
				}
				break;
			}
		}
	}
}
